<?php

/**
* fetch the warehouse
*/
$CFetchers->fetchLstDataHeader($COracle,
                               $jobId,
                               $srcDbHdr,
                               $nHeader,
                               $lstHeader);

$CLFetchers->fetchLstDataDetail($COracle,
                                $jobId,
                                $srcDbSubDtl,
                                $nSubDetail,
                                $lstSubDetail);

for($iRow = 0; $iRow < $nSubDetail; $iRow++){

  $srcWhs   = $lstSubDetail["WAREHOUSE"][$iRow];

  $srcDbWhs = "WHS_" . $srcWhs;

  if($isApprove){

    /**
     * check if we have qty match
     */
    $CFetchers->fetchWhsPchQtyStatus($COracle,
                                     $lstHeader["NOTA_SRC"][0],
                                     $lstSubDetail["MODEL_ID"][$iRow],
                                     $lstSubDetail["QTY"][$iRow],
                                     $SourceDb,
                                     $match);

    if($match["isMatch"] == true){

      /**
       * allocate the inventory
       */
      $CHandlers->insToWhsBalance($COracle,
                                  $lstSubDetail["MODEL_ID"][$iRow],
                                  $lstSubDetail["UNIT"][$iRow],
                                  $lstSubDetail["QTY"][$iRow],
                                  $srcDbWhs);
    }else{

      $Misc->usrDieJs("Error: Qty missmatch ".$lstSubDetail["MODEL_ID"][$iRow]." Warehouse ".$lstSubDetail["WAREHOUSE"][$iRow]." ");
    }
  }else{

    /**
     * deallocate the inventory
     */
    $qty = $lstSubDetail["QTY"][$iRow] * -1;

    $CHandlers->insToWhsBalance($COracle,
                                $lstSubDetail["MODEL_ID"][$iRow],
                                $lstSubDetail["UNIT"][$iRow],
                                $qty,
                                $srcDbWhs);
  }
}
?>